package lib


func init() {
	Probs = append(Probs, Problem{
		Num:         167,
		Discription: "非递减数组的两数之和",
		Level:       2,
		Labels: map[string]int{
			"双指针滑动": 1,
		},
	})
}

func TwoSumSorted(numbers []int, target int) []int {
	left := 0
	right := len(numbers) - 1
	for left < right {
		sum := numbers[left] + numbers[right]
		if sum == target {
			return []int{left + 1, right + 1}
		}

		if sum > target {
			for numbers[right-1] == numbers[right] {
				right--
			}
			right--
			continue
		}

		if sum < target {
			for numbers[left+1] == numbers[left] {
				left++
			}
			left++
			continue
		}
	}

	return []int{}
}